﻿using System;
using System.Reflection;
using LinFu.IoC.Configuration;

namespace CoreEx.DynamicInvoker.Implementation
{
    [Implements(typeof(IHashBuilder))]
    public class HashBuilder : IHashBuilder 
    {
        #region IHashBuilder Members

       
        public int CreateHashCode(MemberInfo memberInfo, Type[] parameterTypes)
        {
            int hashCode = memberInfo.GetHashCode();
            for (int i = 0; i < parameterTypes.Length; i++)
            {
                hashCode ^= parameterTypes[i].GetHashCode() ^ i;
            }
            return hashCode;
        }

        public int CreateHashCode(Type type, string memberName, Type[] parameterTypes)
        {
            int hashCode = type.GetHashCode() ^ memberName.GetHashCode();
            for (int i = 0; i < parameterTypes.Length; i++)
            {
                hashCode ^= parameterTypes[i].GetHashCode() ^ i;
            }
            return hashCode;
        }

        #endregion
    }
}
